<template>
	<view class="container">
		<uni-forms ref="form" :rules="{}" :model="{}">
			<uni-forms-item label=""   style="height: 1rpx;">
				<uni-easyinput v-model="data.title" autoHeight placeholder="请输入标题" />
			</uni-forms-item>
			<uni-forms-item label="" name="" style="display: flex;padding-top: 20px;">
				<uni-easyinput v-model="data.content" type="textarea" autoHeight placeholder="请输入内容" />
			</uni-forms-item>
			<uni-forms-item label="" name="">
				<button type="primary" @click="postComment">发表</button>
			</uni-forms-item>
		</uni-forms>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				data: {
					id: null,
					title: '',
					content:'',
					name:'',
					date:null
				}
			}
		},
		methods: {
			postComment() {
				uni.request({
					url: 'http://localhost:8090/freshmenapp/message/addone',
					method: 'POST',
					data: this.data,
					success: res => {
						if(res.data.success){
							uni.showToast({
								title: '成功',
								icon: 'none'
							}),
							uni.navigateTo({
								url:"/pages/message/message"
							});
							this.data.name = null
						}else{
							uni.showToast({
								title: '失败',
								icon: 'none'
							});
						}
					},
					fail: () => {},
					complete: () => {}
				});
			}
		},
		onLoad(e){
			// 获取待评价食物ID
			this.data.id = e.id || 1
			// 获取当前用户ID
			this.data.name = uni.getStorageSync('userInfo').name
			uni.onTabBarMidButtonTap(function(e) {
				console.log(e)

			})
		}
	}
</script>

<style>
	.container {
		padding: 20px;
		font-size: 14px;
		line-height: 24px;
	}
</style>